# Doc-Encode UTF8, Unix(LF)
# 需要 tar 命令

# 
SHELL = /bin/bash
PWD = `pwd`

##############################################################################
# 编译工具链
export MY_TOOL_CHAIN ?=
export MY_HOST ?=


# 引入工具链
include ../tools.mk

# 引入路径定义
include ../path.mk


##############################################################################
# 源码等路径

PATH_cur := $(MY_PATH)/openssl
PATH_tmp := $(MY_PATH)/openssl/tmp
PATH_file := $(PATH_cur)/openssl-1.1.1w.tar.gz
PATH_src := $(PATH_tmp)/openssl-1.1.1w


##############################################################################
# 函数定义

PARAM_config:=CC=$(CC) CXX=$(CXX) --prefix=$(MY_PATH_PREFIX)
PARAM_config+= no-asm
PARAM_config+= no-async
PARAM_config+= no-shared


# make preopen, 解压包准备文件等
define mk_preopen
	$(MKDIR_P) $(PATH_tmp);
	tar -xzf ${PATH_file} -C ${PATH_tmp};
endef

# make configure, 配置代码环境
# -m64 选项在部分嵌入式编译器下, 不定义支持; 需要去除
define mk_configure
	@echo "PATH_src=$(PATH_src)";
	@echo "PARAM_config=$(PARAM_config)";
	@cd $(PATH_src) && ./config $(PARAM_config);

	# remove -m64
	sed -i '1,300s/-m64//g' $(PATH_src)/Makefile;
endef

# make 
define mk_all
	@cd $(PATH_src) && $(MAKE) -C .;
endef

# make install
define mk_install
	@cd $(PATH_src) && $(MAKE) -C . install_sw;
endef

##############################################################################
# 目标

# make 目标
.PHONY: all clean install

all:
	$(mk_preopen)
	$(mk_configure)
	$(mk_all)

clean:
	$(RM_RF) $(PATH_tmp)

install:
	$(mk_install)
